package chapter1_7_interrupt;

/**
 * @author huayuhao
 * @date 2020/12/15 18:25
 */
public class Interrupt2Test {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() ->{
            try {
                System.out.println("睡200s");
                Thread.sleep(200* 1000);
                System.out.println("睡醒了");
            } catch (InterruptedException e) {
                System.out.println("睡眠被打断了");
                e.printStackTrace();
            }

        });
        // 启动线程
        thread.start();
        // 确保线程进入休眠
        Thread.sleep(1000);
        // 打断
        thread.interrupt();
        // 等待线程执行完毕
        thread.join();
        System.out.println("main over");
    }
}
